package com.zsy.common;

import com.zsy.pojo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    //@ExceptionHandler表示出现异常用此方法处理，value表示要处理的的异常类型
    @ExceptionHandler(value = Exception.class)
    public R<String> handlerException(Exception e){
        log.info("============异常处理============");
        //打印错误信息
        e.printStackTrace();

        return R.error(e.getMessage());
    }

}
